import { useEffect } from "react"
import {
  BrowserRouter,
  Routes,
  Route,
  useNavigate,
} from "react-router-dom"
import { ConfigProvider } from 'antd'
import zn_CN from 'antd/lib/locale-provider/zh_CN'
import Login from "./pages/Login"
import Main from "./pages/Main"
function Redirect({ to }) {
  let navigate = useNavigate();
  useEffect(() => {
    navigate(to);
  });
  return null
}



function App() {

  const fetdata = () => {
    return new Promise((resolve, reject) => {
      resolve({ data: 111 })
    }).then((data) => {
      console.log(data)
    })
  }


  useEffect(() => {
    fetdata()
  }, [])

  // src/utils/setRem.js
  function setRootFontSize() {
    const screenWidth = document.documentElement.clientWidth;
    // 假设设计稿宽度为 1920px，可根据实际情况修改
    const designWidth = 1920;
    // 设计稿中 1rem 对应的像素值，这里设为 100px 方便计算
    const baseFontSize = 16;
    const fontSize = (screenWidth / designWidth) * baseFontSize;
    document.documentElement.style.fontSize = fontSize + 'px';
  }

  useEffect(() => {
    // 页面加载完成时设置根元素的 font-size
    setRootFontSize();
    // 监听窗口大小改变事件
    const handleResize = () => {
      setRootFontSize();
    };
    window.addEventListener('resize', handleResize);

    // 组件卸载时移除事件监听
    return () => {
      window.removeEventListener('resize', handleResize);
    };
  }, []);

  return (
    <ConfigProvider locale={zn_CN}>
      <BrowserRouter>
        <Routes>
          <Route path='/login' element={<Login />} />
          <Route path='/main/*' element={<Main />} />
          <Route path='/' element={<Redirect to="/login" />} />
        </Routes>
      </BrowserRouter>
    </ConfigProvider>
  );
}

export default App;
